﻿using System;
using System.Collections.Generic;
using Model.Enums;
using System.Linq;

namespace Model.Entities
{
    [Serializable]
    public class CardInformation
    {
        public enum Fields
        {
            CardName,
            Url,
            Status
        }

        public string CardName { get; set; }
        public string Attribute { get; set; }
        public string[] Types { get; set; }
        public int Level { get; set; }
        public int Rank { get; set; }
        public int? Atk { get; set; }
        public int? Def { get; set; }
        public string[] CardEffectTypes { get; set; }
        public string CardDescription { get; set; }
        public Dictionary<string,string[]> CardSearchCategories { get; set; }
        public string CardNumber { get; set; }
        public string Property { get; set; }
        public string Url { get; set; }
        public string ImageUrl { get; set; }
        public string ImageThumbnailUrl { get; set; }
        public string Status
        {
            get { return CardStatus.ToString(); }
        }
        public CardStatus CardStatus { get; set; }
        
        public bool isMonster
        {
            get { return string.IsNullOrEmpty(Property); }
        }

        public bool isSpell
        {
            get { return !string.IsNullOrEmpty(Property) && Types[0].Contains("Spell"); }
        }

        public bool isTrap
        {
            get { return !string.IsNullOrEmpty(Property) && Types[0].Contains("Trap"); }
        }

        public int SpeedSpell
        {
            get
            {
                if(isMonster)
                {
                    if (CardEffectTypes.Any(c => c.ToLower().Contains("ignition") || c.Contains("trigger") || c.Contains("flip")))
                        return 1;
                    if (CardEffectTypes.Any(c => c.ToLower().Contains("quick")))
                        return 2;
                }
                else if(isSpell)
                {
                    if (Property.ToLower().Contains("normal") || Property.ToLower().Contains("equip") || Property.ToLower().Contains("continuous") || Property.ToLower().Contains("field") || Property.ToLower().Contains("ritual"))
                        return 1;
                    if (Property.ToLower().Contains("quick"))
                        return 2;
                }
                else
                {
                    if (Property.ToLower().Contains("normal") || Property.ToLower().Contains("continuous"))
                        return 2;
                    if (Property.ToLower().Contains("counter"))
                        return 3;
                }
                return 1;
            }
        }

        public CardInformation()
        {
            CardStatus = CardStatus.NotDownload;
        }
    }
}